import Vue from "vue";
import Router from "vue-router";

Vue.use(Router);

/* Layout */
import Layout from "@/layout";

// 常量路由
export const constantRoutes = [
  // 登录的路由
  {
    path: "/login",
    component: () => import("@/views/login"),
    hidden: true,
  },
  // 404路由
  {
    path: "/404",
    component: () => import("@/views/404"),
    hidden: true,
  },
  // 首页的路由
  {
    path: "/",
    component: Layout,
    redirect: "/dashboard",
    children: [
      {
        path: "dashboard",
        name: "Dashboard",
        component: () => import("@/views/dashboard/index"),
        meta: { title: "首页", icon: "dashboard" },
      },
    ],
  },
];
// 2.异步路由
export const asyncRoutes = [
  //权限相关的路由
  {
    name: "Acl",
    path: "/acl",
    component: Layout,
    redirect: "/acl/user/list",
    meta: {
      title: "权限管理",
      icon: "el-icon-lock",
    },
    children: [
      {
        name: "User",
        path: "user/list",
        component: () => import("@/views/acl/user/list"),
        meta: {
          title: "用户管理",
        },
      },
      {
        name: "Role",
        path: "role/list",
        component: () => import("@/views/acl/role/list"),
        meta: {
          title: "角色管理",
        },
      },
      {
        name: "RoleAuth",
        path: "role/auth/:id",
        component: () => import("@/views/acl/role/roleAuth"),
        meta: {
          activeMenu: "/acl/role/list",
          title: "角色授权",
        },
        hidden: true,
      },
      {
        name: "Permission",
        path: "permission/list",
        component: () => import("@/views/acl/permission/list"),
        meta: {
          title: "菜单管理",
        },
      },
    ],
  },
  // 商品管理的路由
  {
    path: "/product",
    component: Layout,
    meta: { title: "商品管理", icon: "el-icon-zoom-in" },
    //不关一级路由还是二级路由都需要命名，命名名字必须和老师一模一样的[菜单权限，通过name进行匹配的]
    name: "Product",
    //二级路由
    children: [
      {
        path: "trademark", //一定要注意,路径path单词都是小写的
        component: () => import("@/views/product/trademark"),
        meta: { title: "品牌管理", icon: "el-icon-camera" },
        name: "Trademark",
      },
      {
        path: "attr",
        component: () => import("@/views/product/attr"),
        meta: { title: "平台属性管理", icon: "el-icon-s-operation" },
        name: "Attr",
      },
    ],
  },
];
//3:任意路由
export const ryRoute = { path: "*", redirect: "/404", hidden: true };

//  进行路由配置
const createRouter = () =>
  new Router({
    //滚动条的滚动行为
    scrollBehavior: () => ({ y: 0 }),
    //配置路由信息:目前不同的用户展示都是常量路由
    routes: constantRoutes,
  });

const router = createRouter();

// Detail see: https://github.com/vuejs/vue-router/issues/1234#issuecomment-357941465
export function resetRouter() {
  const newRouter = createRouter();
  router.matcher = newRouter.matcher; // reset router
}

export default router;
